<template>
  <div class="card" >
    <!-- 轮播图 -->
    <div class="swipe">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in banner" :key="index">
          <div class="van-swipe-item">
            <img class="swipeImg" :src="item.picUrl" alt="" />
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>

     <!-- 商品列表 -->
    <div class="floor" v-for="(c1,index) in floorList" :key="index">
      <div class="title">
        <p class="title1">{{c1.category.name}}</p>
        <p class="title2">{{c1.category.frontName}}</p>
      </div>
      <div class="content">
        <div class="item" v-for="(c2,index) in c1.itemList" :key="index">
          <img class="show" :src="c2.listPicUrl" alt="">
          <div class="name">{{c2.name}}</div>
          <div class="price">
            <div class="priceItem">
              <p class="price1">￥{{c2.retailPrice}}</p>
              <p class="price2">￥{{c2.sortOriginPrice}}</p>
            </div>
          </div>
          <div class="discount">
            <p class="time">限时优惠</p>
            <p class="ing">正在抢购中</p>
          </div>
        </div>
      </div>
    </div>

    <TabbarServe></TabbarServe>
  </div>
</template>

<script lang="ts">
export default {
  name: 'Cart',
  // props: ['navList']

};
</script>

<script lang="ts" setup>
import { ref, onMounted, watch,computed } from 'vue';
import { useRoute } from 'vue-router';
import { useCardStore } from '../../store/card';

const value = ref('');
const active = ref(0);

const cardStore = useCardStore();
const cardData = ref();
cardData.value = cardStore.cardData;
const banner = ref()
banner.value = cardStore.banner
const floorList = ref()
floorList.value = cardStore.floorList

let route = useRoute();
let { categoryId } = route.query as any;
// console.log(categoryId);





onMounted(() => {
  cardStore.getCardData();
});

watch(
  () => cardStore.cardData,
  newValue => {
    // console.log('newValue', newValue);
    cardData.value = newValue;
  },
  {
    immediate: true,
    deep: true
  }
);
watch(
  () => cardStore.floorList,
  newValue => {
    // console.log('newValue', newValue);
    floorList.value = newValue;
  },
  {
    immediate: true,
    deep: true
  }
);
watch(
  () => cardStore.banner,
  newValue => {
    // console.log('newValue', newValue);
    banner.value = newValue;
  },
  {
    immediate: true,
    deep: true
  }
);

// console.log('cardData111', cardData);
// console.log("floorList", floorList)
// console.log("banner111", banner)

</script>

<style lang="less" scoped>
.card{
  height: 100%;
  width: 100%;
  background-color: #eeeeee;
  .swipe {
  .my-swipe {
    width: 100%;
    height: 148px;
    .van-swipe-item {
      // width: 100%;
      // height: 150px;
      background-color: aquamarine;
      padding: 0;
      .swipeImg {
        height: 148px;
        width: 100%;
      }
    }
  }
}
.floor {
    width: 100%;
    margin-top:10px;
    background-color: #fff;
    .title {
      height: 60px;
      display: flex;
      flex-direction: column;
      align-items: center;
      line-height: 25px;
      .title1 {
        font-size: 16px;
        color: #333333;
        margin: 0;
      }
      .title2 {
        font-size: 12px;
        color: #999999;
        margin: 0;
      }
    }
    .content {
      width: 100%;
      display: flex;
      // justify-content: space-around;
      
      .item {
        width: 50%;
        display: flex;
        flex-direction: column;
        margin-left: 10px;
        background-color: #ffffff;
        .show {
          width: 172.5px;
          height: 172.5px;
        }
        .name {
          width: 172.5px;
          height: 45px;
          font-size: 15px;
        }
        .price {
          width: 172.5px;
          height: 30px;
          padding-right: 3px;
          text-align: center;
          margin-bottom: 5px;
          .priceItem {
            display: flex;
            height: 30px;
            align-items: center;
           
            .price1 {
              width: 50px;
              height: 22px;
              font-size: 20px;
              margin: 0 3px;
              color: red;
              font-weight: bold;
            }
            .price2 {
              padding-left: 8px;
              width: 25px;
              height: 12px;
              // line-height: 10px;
              font-size: 12px;
              text-decoration: line-through;
            }
          }
        }
        .discount {
          background-color: #ffe9eb;
          width: 172.5px;
          height: 30px;
          display: flex;
          align-items: center;
          margin-bottom: 20px;
          .time {
            width: 55px;
            height: 23px;
            line-height: 23px;
            text-align: center;
            background-color: red;
            color: #ffffff;
            border-radius: 24px;
            font-size: 12px;
            margin-left: 3px;
          }
          .ing {
            width: 60px;
            height: 19px;
            font-size: 12px;
            color: red;
            margin-left: 3px;
          }
        }
      }
    }
  }
}
</style>
